import urllib.request
url='https://www.baidu.com/s?wd=ip'
# 自定义请求头，伪装成正常浏览器（防止被服务器识别为爬虫）
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36 Edg/136.0.0.0'
}

# 创建一个带有请求头的 Request 对象（这样才能伪装成功）
req = urllib.request.Request(url, headers=headers)
proxies={
    'http': '117.42.94.53:19463'
}
handler=urllib.request.ProxyHandler(proxies=proxies)
opener=urllib.request.build_opener(handler)
response=opener.open(req)
with open('ip.html','w',encoding='utf-8') as f:
    f.write(response.read().decode('utf-8'))